﻿//
//  main.cs
//
//  Author:
//       Antonio J. Nebro <antonio@lcc.uma.es>
//
//  Copyright (c) 2011 Antonio J. Nebro
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
// 
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.using System;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using jmetal.core;
using jmetal.problems;
using jmetal.experiments.settings;

namespace jmetal.experiments
{
  public class main
  {
    public static void Main(string[] args)
    {
      Algorithm algorithm;

      Dictionary<string, object> parameters;

      String algorithmName = "";
      String problemName = "Fonseca";
      // Default problem

      if ((args.Length < 1) || (args.Length > 2))
      {
        Console.WriteLine("Sintax error. Usage: ");
        Console.WriteLine("a) jmetal algorithm ");
        Console.WriteLine("b) jmetal algorithm problemName");
        Environment.Exit(-1);
      }
      else if (args.Length == 1)
      {
        algorithmName = args[0];
      }
      else if (args.Length == 2)
      {
        algorithmName = args[0];
        problemName = args[1];
      }

      Object settingsParams = problemName;
      SettingsFactory sf = new SettingsFactory();
      Settings settings = sf.getSettingsObject(algorithmName, settingsParams);
      //settings = (new SettingsFactory ()).getSettingsObject (algorithmName, settingsParams);
      algorithm = settings.configure();

      DateTime startTime = DateTime.Now;
      SolutionSet population = algorithm.execute();
      DateTime stopTime = DateTime.Now;
      TimeSpan estimatedTime = stopTime - startTime;

      Console.WriteLine("Total execution time: " + estimatedTime + "ms");
      Console.WriteLine("Variables values have been writen to file VAR");
      population.printVariablesToFile("VAR");
      Console.WriteLine("Objectives values have been writen to file FUN");
      population.printObjectivesToFile("FUN");
    }
  }
}